import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';


@Injectable()
export class HttpProvider {

  constructor(public http: HttpClient) {
    console.log('Hello HttpProvider Provider');
  }
  request(method: string, url: string, params?) {
    // 配置请求头
    let headers = new HttpHeaders();
    headers = headers.set('x-token', 'token');
    // 请求方式
    let resutObs = null;
    switch (method) {
      case 'GET':
      resutObs = this.http.get(url);
      break;
      case 'POST':
      resutObs = this.http.post(url, params);
      break
    }
    return resutObs;
    // if (method === 'GET') {
    //   return this.http.get(url, { headers }).pipe();
    // } else if (method === 'POST') {
    //   return this.http.post(url, params, { headers }).pipe();
    // }
  }
}
